<!-- 出库列表 -->
<template>
	<div class="zs-table-page-container">
		<div class="zs-card-sm zs-space-bottom zs-layout-flex-row zs-layout-justify-between">
			<span>
				<el-input v-model="queryParams.inventoryName" class="zs-select-md zs-space-right-sm" placeholder="清单名称" disabled />
				<el-input v-model="queryParams.materielName" class="zs-select-md zs-space-right-sm" placeholder="物料名称" clearable @blur="queryList" />
				<el-input v-model="queryParams.specificationType" class="zs-select-md zs-space-right-sm" placeholder="规格型号" clearable @blur="queryList" />
				<el-button class="zs-btn-plain" @click="queryList" v-btnPermi="{ permis: ['p_btn_property_project_materiel_into_list_query'] }"> 查询 </el-button>
			</span>
		</div>

		<!-- teble -->
		<div class="zs-card zs-table-page-content">
			<el-table class="zs-table-page-main" :data="tableData.data" v-loading="tableData.loading" stripe>
				<el-table-column type="index" label="序号" width="60" align="center" :index="(index) => index + 1 + (tableData.currentPage - 1) * curPageSize" />
				<el-table-column prop="materielName" label="物料名称" minWidth="120" show-overflow-tooltip align="left" :formatter="defaultTableData" />
				<el-table-column prop="specificationType" label="规格型号" minWidth="120" show-overflow-tooltip align="left" :formatter="defaultTableData" />
				<el-table-column prop="materielTypeValue" label="类型" minWidth="120" show-overflow-tooltip align="left" :formatter="defaultTableData" />
				<el-table-column prop="brand" label="品牌" minWidth="120" show-overflow-tooltip align="left" :formatter="defaultTableData" />
				<el-table-column prop="location" label="存放位置" minWidth="120" show-overflow-tooltip align="center" :formatter="defaultTableData" />
				<el-table-column prop="num" label="可用量" minWidth="120" show-overflow-tooltip align="center" :formatter="defaultTableData" />
				<el-table-column prop="" label="操作" width="90" align="center">
					<template #default="{ row }">
						<el-button class="zs-link" link size="small" @click="openDrawer(false, 'add', row, 'base')" v-btnPermi="{ permis: ['p_btn_property_project_materiel_into_list_out'] }">出库</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="zs-space-top-sm zs-table-page-pagination">
				<el-pagination v-model:currentPage="tableData.currentPage" v-model:page-size="curPageSize" :page-sizes="curPageSizes" :small="true" :background="true" layout="total, sizes, prev, pager, next, jumper" :total="tableData.total" @size-change="pageChange('size', $event)" @current-change="pageChange('page', $event)" />
			</div>
		</div>
	</div>

	<!--出库抽屉 -->
	<DrawerStorageOut :isShow="drawer.base.isShowDrawer" :isReadOnly="drawer.base.isReadOnly" :handleType="drawer.base.handleType" :currentRow="currentRow.data" @close="closeDrawer($event, 'base')"> </DrawerStorageOut>
</template>

<script setup>
	import DrawerStorageOut from './components/drawerStorageOut.vue';
	import { storageOutListApi, suppliesInfoApi } from '@/api/supplies.js';
	import { ref, reactive, VueElement } from 'vue';
	import { useStore } from 'vuex';
	import { useRouter, useRoute } from 'vue-router';
	import { defaultTableData, getDictoryTxt } from '@/utils/publicUtils';

	const router = useRouter();
	const route = useRoute();
	let store = useStore();
	const curPageSizes = ref(store.state.uiPageSizes);
	const curPageSize = ref(store.state.uiPageSizeDefault);

	// 列表 filed
	let tableData = reactive({
		currentPage: 1,
		total: 0,
		loading: false,
		data: [],
	});

	//查询条件
	let queryParams = reactive({ materielId: route.query.id, pageNumber: 1, pageSize: curPageSize.value });

	// 抽屉相关
	let currentRow = reactive({ data: {} });
	let drawer = reactive({
		base: {
			handleType: '',
			isReadOnly: false,
			isShowDrawer: false,
		},
	});

	const openDrawer = (flag, handleType, row, drawerType) => {
		drawer[drawerType].isReadOnly = flag;
		drawer[drawerType].isShowDrawer = true;
		drawer[drawerType].handleType = handleType;
		currentRow.data = row;
	};

	const closeDrawer = (data, drawerType) => {
		drawer[drawerType].isShowDrawer = data.isShow;
		data.isRefresh && queryList('init');
	};

	// 列表数据源
	const queryList = async init => {
		if (process.env.NODE_ENV !== 'development') {
			let portalResourceList = JSON.parse(localStorage.getItem('portalResourceList'));
			if (init != 'init' && !portalResourceList.includes('p_btn_property_project_materiel_into_list_query')) return;
		}
		tableData.loading = true;
		let res = await storageOutListApi(queryParams);
		if (res.data.code !== 200) return;
		tableData.data = res.data.data.list || [];
		tableData.total = res.data.data.total || 0;
		tableData.loading = false;
	};

	// 分页
	const pageChange = (type, size) => {
		if (type == 'size') {
			queryParams.pageSize = size;
		} else {
			queryParams.pageNumber = size;
		}
		queryList('init');
	};

	//物料详情
	const getSuppliesInfo = async () => {
		let res = await suppliesInfoApi({ id: route.query.id });
		if (res.data.code !== 200) return;
		queryParams.inventoryName = res.data.data.inventoryName;
	};

	queryList('init');
	getSuppliesInfo();
</script>

<script>

</script>
